using System;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class MsgBoxBase : Button
	{
		private static string[] msgBkInfoArray = new string[]
		{
			"Resource/Img/Chat/chatfrom_bg_normal.9.png",
			"Resource/Img/Chat/chatfrom_bg_normal.9.png",
			"Resource/Img/Chat/chatto_bg_normal.9.png",
			"Resource/Img/Chat/chatto_bg_normal.9.png"
		};
		private static Thickness[] contentMargin = new Thickness[]
		{
			new Thickness(22.0, 10.0, 10.0, 10.0),
			new Thickness(9.0, 9.0, 21.0, 10.0)
		};
		private bool isPressed;
		private NinePatchImg BkImg;
		private Panel ContentArea;
		public static DependencyProperty IsSendProperty = DependencyProperty.Register("IsSend", typeof(bool), typeof(MsgBoxBase), new PropertyMetadata(true, new PropertyChangedCallback(MsgBoxBase.OnItemPropertyChanged)));
		public bool IsSend
		{
			get
			{
				return (bool)base.GetValue(MsgBoxBase.IsSendProperty);
			}
			set
			{
				base.SetValue(MsgBoxBase.IsSendProperty, value);
			}
		}
		protected virtual Thickness[] GetContentMargin()
		{
			return MsgBoxBase.contentMargin;
		}
		protected virtual string[] GetBkImgArray()
		{
			return MsgBoxBase.msgBkInfoArray;
		}
		private void RefreshImageSource()
		{
			int num;
			if (this.isPressed)
			{
				if (this.IsSend)
				{
					num = 3;
				}
				else
				{
					num = 1;
				}
			}
			else
			{
				if (this.IsSend)
				{
					num = 2;
				}
				else
				{
					num = 0;
				}
			}
			this.BkImg.Src = this.GetBkImgArray()[num];
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.BkImg = (base.GetTemplateChild("BkImg") as NinePatchImg);
			this.ContentArea = (base.GetTemplateChild("ContentArea") as Panel);
			this.RefreshMargin();
			this.RefreshImageSource();
		}
		private void RefreshMargin()
		{
			if (this.ContentArea != null)
			{
				if (this.IsSend)
				{
					this.ContentArea.set_Margin(this.GetContentMargin()[1]);
					return;
				}
				this.ContentArea.set_Margin(this.GetContentMargin()[0]);
			}
		}
		protected override void OnIsPressedChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			base.OnIsPressedChanged(dependencyPropertyChangedEventArgs_0);
			if (dependencyPropertyChangedEventArgs_0.get_NewValue() != dependencyPropertyChangedEventArgs_0.get_OldValue())
			{
				this.isPressed = (bool)dependencyPropertyChangedEventArgs_0.get_NewValue();
				this.RefreshImageSource();
			}
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == MsgBoxBase.IsSendProperty)
			{
				(dependencyObject_0 as MsgBoxBase).OnIsSendPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnIsSendPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (this.BkImg != null)
			{
				this.RefreshImageSource();
			}
			this.RefreshMargin();
		}
	}
}
